home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / basic / BlitzLstJun02.lha / BlitzLstJun02 / attachments / mail_55 / priority.asc
Text File  |  2002-09-02  |  2KB  |  66 lines

  1. ; Function : SetPriority { priority }
  2.  
  3. ; Author : Peter Thor - email?
  4. ;          priority check added by JLB
  5.  
  6. ; Sets the priority of your program to whatever you want.
  7. ; Negative numbers mean higher priority (roughly : more CPU
  8. ; time). Priority can be from -127 to +127. Positive numbers
  9. ; mean higher priority. It's recommended that most programs
  10. ; shouldn't use higher than 5-10 as far as I remember, but
  11. ; as long as you know what you're doing, you can crank it
  12. ; up to whatever you want (up to 127!), or make it low if
  13. ; it doesn't need much CPU time).
  14.  
  15. ; Returns value of priority before function was called, so
  16. ; you just call SetPriority {returned value} to put it
  17. ; back how it was.
  18.  
  19. ; Couldn't really decide how to return a failure, so just
  20. ; returns 0, which is still a valid value! Adjust it to suit
  21. ; your needs!
  22.  
  23. Function.w SetPriority{newpriority.w}
  24.  
  25.   If newpriority<-127 OR newpriority>127 Then Function Return 0
  26.  
  27.   Forbid_                     ;lock system to check for task
  28.  
  29.   *task.l=FindTask_(*crap.l)  ;*crap.l is only a NULL-Pointer
  30.                               ;this way the task of the program itself
  31.                               ;is returned
  32.  
  33. ; set the new priority:
  34.   oldpriority.w=SetTaskPri_(*task,newpriority.w)
  35.  
  36.   Permit_                     ;and return the system
  37.  
  38. Function Return oldpriority.w
  39.  
  40. End Function
  41.  
  42. ; demo :
  43.  
  44. ;; NOTE : Use XOpa or similar program to see priority. If you're
  45. ;; running from Blitz, it'll be the "Blitz ][ Program Proc" you're
  46. ;; looking for. With most of these type of programs, you'll have
  47. ;; to update the task list to see the change.
  48.  
  49. ;; I use Executive, which I think modifies the priority you
  50. ;; set, so I sometimes get some weird number listed, but it
  51. ;; basically works!
  52.  
  53. ; Repeat
  54.  
  55. ;   Print "Priority (-127 to 127), 1000 to end : "
  56. ;   a.w=Edit(4)
  57. ;   If a=1000 Then End
  58.  
  59. ;   oldpri.w=SetPriority {a}
  60. ;   NPrint "The old priority was : ",oldpri
  61. ;   NPrint ""
  62.  
  63. ; Forever
  64.  
  65.  
  66.